<template>
  <div class="profile-container">
    <div class="profile-card">
      <h2 class="profile-title">个人资料</h2>
      <el-form
          :model="data.user"
          ref="formRef"
          label-width="120px"
          label-position="right"
          class="profile-form"
      >
        <el-form-item label="用户名" prop="username">
          <el-input
              disabled
              v-model="data.user.username"
              autocomplete="off"
              placeholder="用户名"
          />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input
              v-model="data.user.name"
              autocomplete="off"
              placeholder="请输入姓名"
          />
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input
              v-model="data.user.phone"
              autocomplete="off"
              placeholder="请输入电话"
          />
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input
              v-model="data.user.email"
              autocomplete="off"
              placeholder="请输入邮箱"
          />
        </el-form-item>
        <div class="form-footer">
          <el-button
              type="primary"
              size="large"
              round
              @click="save"
          >
            保存
          </el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import { reactive, ref } from "vue";
import request from "@/utils/request";
import { ElMessage } from "element-plus";

const data = reactive({
  user: JSON.parse(localStorage.getItem('user') || '{}'),
});

const save = () => {
  request.put('/admin/update', data.user).then(res => {
    if (res.code === '200') {
      ElMessage.success('保存成功');
    } else {
      ElMessage.error(res.msg);
    }
  });
};
</script>

<style scoped>
.profile-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: linear-gradient(135deg, #eceef1, #9c9d9f, #49494a);
  padding: 20px;
}

.profile-card {
  background: #fff;
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 500px;
  text-align: center;
}

.profile-title {
  margin-bottom: 20px;
  font-size: 24px;
  font-weight: bold;
  color: #333;
}

.profile-form {
  margin-top: 20px;
}

.el-input {
  border-radius: 6px;
}

.form-footer {
  margin-top: 30px;
}

.el-button {
  padding: 12px 32px;
  font-size: 16px;
  background: linear-gradient(90deg, #c4c7cc, #3b3b3c);
  border: none;
  color: #fff;
  box-shadow: 0 4px 8px rgba(67, 100, 247, 0.3);
  transition: all 0.3s ease;
}

.el-button:hover {
  background: linear-gradient(90deg, #3b3b3c, #c4c7cc);
  box-shadow: 0 6px 12px rgba(67, 100, 247, 0.4);
}
</style>
